package com.xw.musicplayer;

import android.app.Activity;
import com.xw.musicplayer.floatView.FloatWindowManager;

public class MusicPlayer extends BaseMusicPlayer{

    private static MusicPlayer instance;
    private boolean flowIsInit = false;

    public MusicPlayer(Activity activity) {
        super(activity);
        FloatWindowManager.createFlowWindow(activity);
    }

    public static void initialize(Activity activity) {
        if (instance == null) {
            synchronized (MusicPlayer.class) {
                if (instance == null) {
                    instance = new MusicPlayer(activity);
                }
            }
        }
    }

    public static MusicPlayer getInstance() {
        if (instance == null) {
            throw new NullPointerException("请先初始化音频播放器");
        }
        return instance;
    }

    public static boolean isInitialize() {
        return instance != null;
    }

    public void showFloatWindow() {
        if (!flowIsInit) {
            FloatWindowManager.setChangeListener();
            flowIsInit = true;
        }
        FloatWindowManager.show();
    }

    public void hideFloatWindow() {
        FloatWindowManager.hide();
    }

    public void removeFloatWindow() {
        hideFloatWindow();
        FloatWindowManager.removeFloatWindow();
    }

}
